﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace weighing
{
    /// <summary>
    /// 权限菜单显示
    /// </summary>
    public class PermissionVisibilityConveter : System.Windows.Data.IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string permissionKey = parameter.ToString();

            if (App.CurrentUser == null) return Visibility.Collapsed;
            //开发者
            if (App.CurrentUser.roleType == (int)UserRoleType.Developer) return Visibility.Visible;
            //没有任何权限 collapsed
            if (App.CurrentUser.Permissions == null || App.CurrentUser.Permissions.Count <= 0) return Visibility.Collapsed;
            //未传参
            if (string.IsNullOrEmpty(permissionKey)) return Visibility.Collapsed;

            return UserDao.Instance.HasPermission(permissionKey)? Visibility.Visible: Visibility.Collapsed; 
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
